<template>
  <div class="swStInputPassengerWork">
    <basic-container>
      <avue-crud
        ref="crud"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :page.sync="page"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="refreshChange"
        @on-load="refreshChange">
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm);getList()}" icon="el-icon-delete">清空</el-button>
        </template>
        <template slot-scope="scope" slot="menuRight">
          <el-button type="primary"  size="mini" @click="auditAll">一键审批</el-button>
          <el-button type="primary"  size="mini" @click="exportData">导出</el-button>
        </template>
        <template slot-scope="scope" slot="lineCodeSearch">
          <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" filterable>
            <el-option
              v-for="(item,index) in lineCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="stationCodeSearch">
          <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" @change="changeStation" filterable>
            <el-option
              v-for="(item,index) in stationCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="conductorNameSearch">
          <el-select v-model="searchForm.conductorCode" placeholder="请选择" style="width: 150px" filterable>
            <el-option
              v-for="(item,index) in userList"
              :key="index"
              :label="item.nikename"
              :value="item.userCode">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="conductorCodeSearch">
          <el-select v-model="searchForm.conductorCode" placeholder="请选择" style="width: 150px" filterable>
            <el-option
              v-for="(item,index) in userList"
              :key="index"
              :label="item.userCode"
              :value="item.userCode">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button type="text" size="small" v-if="scope.row.auditStatus==1" plain @click.stop="previewEditor(scope.row,1)">审批</el-button>
          <el-button type="text" size="small" v-if="scope.row.auditStatus!=1" plain @click.stop="previewEditor(scope.row,2)">查看</el-button>
        </template>
      </avue-crud>
    </basic-container>
    <transactionAudit v-if="isTransactionAudit" ref="transactionAudit"></transactionAudit>
  </div>
</template>

<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {mapGetters} from 'vuex';
  import transactionAudit from './transactionAudit';
  import ElInput from "../../../../../../node_modules/element-ui/packages/input/src/input";
  import {
    getgetStationCodes,
    getLineCodes, getSwPmDeviceOperationCodeList,
    getSysUserToLS,
    setSearchFiledsEmpty
  } from "../../../../../api/subwayRat/commonCheck";
  import {exportDataToExcel} from "../../../../../api/subwayRat/exportSelf";
  import transitUtil from "../../../../../api/subwayRat/transitUtil";
  import {tableOption,getSwStInputPassengerWork,getSysUserToLine,auditAll
  } from '../../../../../api/subwayRat/conductorDifferences/passengersTransaction/passengersTransactionAudit/swStInputPassengerWork';
  export default {
    components: {ElInput,transactionAudit},
    name: 'swStInputPassengerWork',
    data() {
      return {
        btnType : 0,
        userList:[],
        lineCodes : [],
        stationCodes:[],
        rowData : {},
        selectKeys:[], //存放对像
        selectKeyVals:[], //存放值
        option: tableOption,
        listLoading: true,
        isTransactionAudit: false,
        searchForm:{
          lineCode : '9',
          stationCode : '',
          conductorCode : '',
          auditStatus:'1',
          startdate:'',
          enddate:''
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          current: 1,// 当前页数
          pageSize: 20, // 每页显示多少条,
          size: 20,// 每页显示多少条
          isAsc: false// 是否倒序
        },
        list : []
      }
    },
    computed: {
    },
    watch: {
    },
    created() {
      this.changeLine("9")
      //this.otherVueAction();
    },
    mounted() {
      getLineCodes().then(res=>{ //获取线路
        this.lineCodes=res;
      });
      // getSysUserToLine({}).then((response)=>{
      //   this.userList = response.data.data;
      // });
    },
    methods: {
      setSearchFiledsEmpty,
      refreshChange() {
        this.getList()
      },
      changeLine(v){ //改变线路时
        getgetStationCodes(v).then(res=>{
          this.stationCodes=res;
          this.searchForm.stationCode='';
        })
        this.userList = [];
        this.searchForm.conductorCode = '';
      },
      async changeStation(v){ //改变车站
        let p = {
          line_code : this.searchForm.lineCode,
          station_code : v
        };
        await getSysUserToLS(p).then((response)=>{
          this.userList = response.data.data;
        });
        this.searchForm.conductorCode = '';
      },
      async auditAll(){
        let th = this;
        if(this.selectKeys.length<=0){
          this.$message.warning("请选择要审批的数据！");
          return;
        }
        this.$confirm('您是否要审批选中数据？', '提示', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning'
        }).then(() => {

        }).then(async() => {
            let p = {
                ids : JSON.stringify(th.selectKeyVals)
            };
            debugger
          await auditAll(p);
          th.getList();
        })
      },
      previewEditor(row,type){
        this.btnType = type;
        if(1!=type && 2 != row.auditStatus){
          this.btnType = 3;
        }
        this.isTransactionAudit = true;
        this.rowData = row;
      },
      async exportData(){ // 导出
        this.searchForm.pageNo=1;
        this.searchForm.pageSize=1000000000;
        this.searchForm.size=1000000000;
        if(this.selectKeys.length>0){
          let newData = JSON.parse(JSON.stringify(this.selectKeys));
          exportDataToExcel(newData,this.option.column,'乘客事务审核');
        }else {
          let res=await getSwStInputPassengerWork(this.searchForm);
          let data = res.data.data.records;
          exportDataToExcel(data,this.option.column,'乘客事务审核');
        }
      },
     getList(){
      const params = this.$route.query;
       console.log(JSON.stringify(params))
      const p = {};
     if (Object.keys(params).length) {
       p.lineCode = params.lineCode;
       p.stationCode = params.stationCode;
       if (params.pathType == "1") {
         p.workDate = params.reprotTime;
         p.stationPersonrName = params.stationPersonrName;
         p.sourceQueryFlag = '1';
       } else {
         p.workDate = params.recordTime;
         p.conductorCode = params.conductorJobNo;
         p.sourceQueryFlag = '1'; //判断是售票员票款差异审核跳转过来的
       }
     }
       this.listLoading = true;
      this.page.size = this.page.pageSize;
      this.page.current = this.page.currentPage;
       //收入日期范围
       let dates1 = this.searchForm.dates1;
       if(dates1!=null && dates1!=''){
         this.searchForm.startdate = dates1[0].substr(0,10);
         this.searchForm.enddate = dates1[1].substr(0,10);
       }
       Object.assign(this.searchForm, this.page);
       this.searchForm.userCode = this.$store.getters.userInfo.userCode;
       getSwStInputPassengerWork(Object.keys(params).length ? p : this.searchForm).then(response => {
       this.list = response.data.data.records;
       this.listLoading = false;
       this.page.total = response.data.data.total;
	 });

 },
      handleFilter(params, done) {
        Object.assign(this.searchForm,params);
        this.getList()
        done()
      },
      selectionChange(list){
        this.selectKeys=list;
        this.selectKeyVals=[];
        for(let i=0;i<list.length;i++){
          this.selectKeyVals.push(list[i].id);
        }
      },
      otherVueAction(){ //供其他Vue页面调用
        let th=this;
        transitUtil.$on('swStInputPassengerWork_call',(param)=>{
          let p={};
          p.lineCode=param.lineCode;
          p.stationCode=param.stationCode;
          p.workDate=param.recordTime;
          p.conductorCode=param.conductorJobNo;
	        p.sourceQueryFlag='1';//判断是售票员票款差异审核跳转过来的
          getSwStInputPassengerWork(p).then((response)=>{
            this.list = response.data.data.records;
            this.listLoading = false;
            this.page.total=response.data.data.total;
          });
        });
      }
    },
  }
</script>
<style lang="scss">
</style>
